package com.authine.cloudpivot.web.api.service.impl;



import cn.hutool.core.util.ObjectUtil;
import com.authine.cloudpivot.web.api.dao.AttachmentMapper;
import com.authine.cloudpivot.web.api.domain.dto.AttachmentDTO;
import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.service.AttachmentsService;
import com.authine.cloudpivot.web.api.view.oss.MultiVO;
import com.authine.cloudpivot.web.api.vo.Attachment;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Slf4j
@Service
public class AttachmentsServiceImpl implements AttachmentsService {

    @Autowired
    private AttachmentMapper attachmentMapper;


    @Override
    public   List<AttachmentDTO> getMultiVO(String projectNo, String settleable, String storeRotation, String storeNum, String startTime, String endTime, String member, String cityName){
        List<Attachment> attachmentList=attachmentMapper.getAttachments(projectNo);
        List<AttachmentDTO> attachmentDTOList=new ArrayList<>();

        for(Attachment attachment:attachmentList){
                String tableName="iden7_"+attachment.getSchemaCode();
                //查询到对应的门店名称和创建人
                Map<String,String> map=attachmentMapper.getStoreInfo(tableName,attachment.getBizObjectId(), settleable, storeRotation, storeNum, startTime, endTime, member, cityName);
                if(ObjectUtil.isNotNull(map) && map !=null && !map.isEmpty()){
                    AttachmentDTO  attachmentDTO=new AttachmentDTO();
                    BeanUtils.copyProperties(attachment,attachmentDTO);
                    attachmentDTO.setCreaterName(map.get("name"));
                    attachmentDTO.setStoreID(map.get("storeID"));
                    attachmentDTO.setStoreName(map.get("storeName"));
                    attachmentDTO.setLastName(attachmentDTO.getStoreName()+"-"+attachmentDTO.getCreaterName() +"-"+attachmentDTO.getPropertyName()+"-"+ attachmentDTO.getName());
                    attachmentDTOList.add(attachmentDTO);
                }
            }

        return attachmentDTOList;
    }






}



